package com.suray.system.run.impl;

import com.suray.system.run.SystemMonitorInterface;
import com.suray.system.run.core.*;
import com.suray.system.run.data.mysql.analyze.DeviceDataStore;
import com.suray.system.run.type.*;

import java.util.Date;
import java.util.List;

public class SystemMonitorImpl implements SystemMonitorInterface {
    private SystemMonitor systemMonitor;

    public int getDeviceErrorNum(String series) {
        DeviceDataStore deviceDataStore = SystemMonitor.monitorDataStore.getDeviceDataStore(series);
        return SystemMonitor.monitorDataStore.getDeviceDataStore(series).getErrorDesList(null, null).size();
    }

    @Override
    public List<ErrorDescription> getDeviceErrorHistory(String series, Date startTime, Date endTime) {
        return SystemMonitor.monitorDataStore.getDeviceDataStore(series).getErrorDesList(startTime, endTime);
    }

    @Override
    public ErrorDescription getCurrentErrorDescription(String series) {
        return systemMonitor.findDeviceErrorDes(series);
    }

    @Override
    public List<OfflineDescription> getDeviceOffLineHistory(String series, Date startTime, Date endTime) {
        return SystemMonitor.monitorDataStore.getDeviceDataStore(series).getOffLineList(startTime, endTime);
    }

    @Override
    public OfflineDescription getCurrentOffLine(String series) {
        return systemMonitor.findDeviceOffLineDes(series);
    }

    @Override
    public List<LowBatteryDescription> getCarLowBatteryInfoHistory(String series, Date startTime, Date endTime) {
        return SystemMonitor.monitorDataStore.getDeviceDataStore(series).getLowBatteryInfoList(startTime, endTime);
    }

    @Override
    public LowBatteryDescription getCurrentLowBatteryInfo(String series) {
        return systemMonitor.findLowBatteryInfo(series);
    }

    @Override
    public List<ChargeInfo> getCarChargeInfoHistory(String series, Date startTime, Date endTime) {
        return SystemMonitor.monitorDataStore.getDeviceDataStore(series).getChargeInfoList(startTime, endTime);
    }

    @Override
    public ChargeInfo getCurrentChargeInfo(String series) {
        return systemMonitor.findDeviceChargeInfo(series);
    }

    @Override
    public int getCarChargeNum(String series) {
        return SystemMonitor.monitorDataStore.getDeviceDataStore(series).getChargeNum();
    }

    @Override
    public int getDeviceNum(DeviceType deviceType) {
        return systemMonitor.getDeviceNum(deviceType);
    }

    @Override
    public List<String> getTaskingDevice(DeviceType deviceType) {
        return systemMonitor.getTaskingDevice(deviceType);
    }

    @Override
    public int getCargoSpaceNum() {
        return systemMonitor.getCargoSpaceNum();
    }

    @Override
    public int getUsedCargoSpaceNum() {
        return systemMonitor.getUsedCargoSpaceNum();
    }

    @Override
    public RgvInfo getRgvInfo(String series) {
        return systemMonitor.getRgvInfo(series);
    }

    @Override
    public LifterInfo getLifterInfo(String series) {
        return null;
    }

    @Override
    public ConveryInfo getConveryInfo(String series) {
        return null;
    }

    @Override
    public int getTaskLeftTime(String taskId) {
        return 0;
    }

    @Override
    public int getTodayDeviceWorkTime(String series) {
        return (int) systemMonitor.getTodayDeviceWorkTime(series);
    }

    @Override
    public long getDeviceWorkTime(String series) {
        return (int) systemMonitor.getDeviceWorkTime(series);
    }

    @Override
    public int getDeviceTotalTaskNum(String series) {
        return SystemMonitor.monitorDataStore.getDeviceDataStore(series).getTaskNum();
    }

    @Override
    public int getDeviceInCargoTaskNum(String series, Date startTime, Date endTime) {
        return SystemMonitor.monitorDataStore.getDeviceDataStore(series).
                getDeviceInCargoTaskNum(startTime, endTime);
    }

    @Override
    public int getDeviceOutCargoTaskNum(String series, Date startTime, Date endTime) {
        return SystemMonitor.monitorDataStore.getDeviceDataStore(series).
                getDeviceOutCargoTaskNum(startTime, endTime);
    }

    @Override
    public int getDeviceTransCargoTaskNum(String series, Date startTime, Date endTime) {
        return SystemMonitor.monitorDataStore.getDeviceDataStore(series).
                getDeviceTransCargoTaskNum(startTime, endTime);
    }

    @Override
    public int getFinishTaskNum(TaskType taskType) {
        return systemMonitor.getFinishTaskNum(taskType);
    }

    @Override
    public int getExecingTaskNum(TaskType taskType) {
        return systemMonitor.getExecingTaskNum(taskType);
    }

    @Override
    public int getCancelTaskNum(TaskType taskType) {
        return systemMonitor.getCancelTaskNum(taskType);
    }

    @Override
    public int getErrorTaskNum(TaskType taskType) {
        return systemMonitor.getErrorTaskNum(taskType);
    }

    @Override
    public int getWaitForExecTaskNum(TaskType taskType) {
        return systemMonitor.getWaitForExecTaskNum(taskType);
    }

    public void init() {
        systemMonitor = new SystemMonitor();
        systemMonitor.init();
    }

    public void run() {
        systemMonitor.run();
    }
}
